package cn.edu.cqu.fredyvia.forum;

import cn.edu.cqu.fredyvia.forum.config.SecurityConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@AutoConfigureBefore(SecurityConfig.class)
@Slf4j
public class MyMvcConfigurer implements WebMvcConfigurer {
    public void addCorsMappings(CorsRegistry registry){
        log.info("跨域已设置");
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
//                .allowedOrigins("http://10.42.0.201:8080")
//                .allowedOrigins("127.0.0.1:7002")
                .allowedMethods("*")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }
}